using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Ants.Utilities
{
    public struct Circle
    {
        public Vector2 center;
        public float radius;

        public Circle(Vector2 center, float radius)
        {
            this.center = center;
            this.radius = radius;
        }
    }

    public struct TangentInfo2D
    {
        public Vector2 worldPos;
        public Vector2 dir;
        public TangentInfo2D(Vector2 position,Vector2 dir)
        {
            this.worldPos = position;
            this.dir = dir;
        }

        public TangentInfo2D(float unparam=0)
        {
            worldPos = Vector2.zero;
            dir=Vector2.zero;
        }
    }

    public struct Polygon2D
    {
        public Vector2[] points;
        public Vector2 GeomCenter
        {
            get { return GetGeometryCenter(points); }
        }

        public Polygon2D(Vector2[] points)
        {
            this.points = points;
        }
        public Polygon2D(Vector2[] points,Transform modelTrans)
        {
            this.points = points;
            TransformBy(modelTrans);
        }

        public static Vector2 GetGeometryCenter(Vector2[] points)
        {
            if(points==null||points.Length==0)
                return Vector2.zero;
            Vector2 acc=Vector2.zero;
            foreach (var p in points)
            {
                acc += p;
            }
            return acc/points.Length;
        }

        private void Offset(Vector2 delta)
        {
            for (int i = 0; i < points.Length; i++)
            {
                    points[i]+= delta;
            }
        }

        public void TransformBy(Transform t)
        {
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = Geometry2D.ModelTransformXY2D(t,points[i]);
            }
        }

        public void InverseTransformBy(Transform t)
        {
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = Geometry2D.InverseModelTransformXY2D(t,points[i]);
            }
        }
    }
    

}

